home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / reply1.zip / REPLY1.ASM < prev    next >
Assembly Source File  |  1988-07-28  |  10KB  |  307 lines

  1. PAGE ,132                ;SET FOR WIDE LISTING
  2. ; REPLY.ASM
  3. ;Created By:  Charles Thurston, Sunnyvale, CA, October 1987
  4. ;Returns ERRORLEVEL to a batch file, depending on user selection of a
  5. ;command parameter line; will time out in 10 seconds (CPU-dependent),
  6. ;returning a default ERRORLEVEL of 0.
  7. ;See REPLY.DOC for usage.
  8.  
  9. ;880112    Toad Hall Tweak, rewrite.  David Kirschbaum, kirsch@braggvax.ARPA
  10. ; - tightened code in general
  11. ; - removed CPU-dependent delay loop, replacing with Int 08H-controlled
  12. ;   delay.
  13. ; - saved about 60 bytes or so despite more "portable" fixes.
  14. ; - My new code is in lower case or flagged with "[TH]".
  15. ;880729
  16. ; - Replaced string tick display with single-char (still staying with
  17. ;   the DOS services rather than a BIOS write-tty service)
  18. ;--------------------------------------------------------------------
  19.  
  20. CR    equ    0DH
  21. LF    equ    0AH
  22.  
  23.  
  24. CODE_SEG SEGMENT para public    'code'
  25.     ASSUME CS:CODE_SEG,DS:CODE_SEG,SS:CODE_SEG,ES:CODE_SEG
  26.  
  27. ;    ORG 100H               ;THIS COMMAND WAS NOT NEEDED
  28.     org    0100H        ;[TH] the hell!
  29. ;====================================================================
  30. ; BEGINNING OF PROGRAM
  31. ;
  32. Reply    proc    near        ;[TH]
  33.     CALL    INPUT        ;GO TO INPUT CHECKING
  34.     CMP    AL,86H        ;WAS THERE AN ERROR(86H)
  35. ;[TH]    JZ    EXIT        ;IF YES, EXIT
  36.     je    Error_Exit    ;carry means error, msg ofs in dx
  37. ;[TH] WAIT is a reserved word for MASM 5.0
  38. ;[TH]    CALL    WAIT        ;GO TO WAITING ROUTINE
  39.     call    Wait1        ;go to waiting routine
  40. ;[TH] If an error, we have a message in dx.
  41. ;We ALSO have at least a CR/LF string in dx even if we succeeded.
  42. ;Ergo : we always print a string on exit.
  43. ;AL will have either 86H (error), or the ERRORLEVEL from the Wait procedure.
  44. Error_Exit:
  45.     push    ax        ;[TH] save error level
  46.     mov    ah,09H        ;Display string
  47.     int    21H        ;ought not disturb AL, but still...
  48.     pop    ax        ;[TH] restore error level
  49. ;[TH] EXIT:
  50.     MOV    AH,4CH        ;terminate program
  51.     INT    21H        ;EXIT WITH CODE IN AL
  52.  
  53. ;====================================================================
  54. ; DATA AREA ------ ESTABLISH TABLES AND SYMBOLS
  55. ;
  56. TABLE    DB    31H DUP(0),'123456789',7H DUP(0),'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  57. TABLE2    DB    6H DUP(0),'ABCDEFGHIJKLMNOPQRSTUVWXYZ',85H DUP(0)
  58. DUPLIST    DB    80H DUP(0)
  59. RESPONSES DB    24H DUP(0)
  60. NONE    DB    'Missing Reply Parameter.',0DH,0AH,'$'
  61. WRONG    DB    'Invalid Reply Parameter.',0DH,0AH,'$'
  62. DOUBLE    DB    'Duplicate Reply Parameter.',0DH,0AH,'$'
  63. ASKTHIS    DB    'RESPONSE:$'
  64. ;[TH] TIMETICK DB    ' .$' no longer used
  65. TIMEOUT DB    ' DEFAULT'
  66. feed    db    0DH,0AH,'$'        ;[TH] share the CR/LF
  67. ;[TH] FEED    DB    0DH,0AH,'$'
  68. Clock    label    dword        ;[TH]
  69.     dw    046CH,0        ;ofs,seg of DOS master clock
  70. ;====================================================================
  71. Reply    endp            ;[TH]
  72.  
  73. ; CHARACTER INPUT AND CHECKING SUBROUTINE
  74. ;
  75. INPUT    proc    near
  76.     CLD            ;CLEAR DF (e.g., insure fwd)
  77.     XOR    CX,CX        ;  "   CX
  78.     MOV    DI,0080H    ;SET DI TO INPUT STRING
  79.     MOV    CL,[DI]        ;PUT COUNT INTO CX
  80.     JCXZ    MISSING        ;IF CX=0 PRINT MISSING & END
  81.     DEC    CX        ;SKIP LEADING SPACE
  82.     MOV    BP,CX        ;PUT CX IN BP FOR LATER
  83.     XOR    AX,AX        ;CLEAR AX
  84.     MOV    SI,0082H    ;SI POINTS TO INPUT STRING
  85. ;[TH]    LEA    DI,RESPONSES+0100H ;DI   "      "  RESPONSES
  86. ;[TH]    LEA    BX,TABLE+0100H    ;BX   "    "  TABLE
  87. ;[TH] author has an obsession with LEAs.  Donno why .. they're slower,
  88. ;more awkward to code.
  89.     mov    di,offset Responses    ;DI points to responses
  90.     mov    bx,offset Table        ;BX points to table
  91. TRANSLATE:
  92.     LODSB            ;PUT [SI] INTO AL, INC SI
  93.     XLAT            ;[BX+AL]=>AL
  94. ;[TH]    CMP    AL,00H        ;CHECK IF VALID CHARACTER
  95.     or    al,al        ;check if valid character
  96.     JZ    INVALID        ;PRINT INVALID AND END
  97.     STOSB            ;STORE AL=>[DI], INC DI
  98.     LOOP    TRANSLATE    ;LOOP UNTIL CX=0
  99.     MOV    CX,BP        ;PUT COUNT INTO CX
  100.     XOR    AX,AX        ;CLEAR AX
  101. ;[TH]    LEA    SI,RESPONSES+0100H    ;SI POINTS TO RESPONSES
  102. ;[TH]    LEA    BX,DUPLIST+0100H    ;BX   "    "  DUPLIST
  103.     mov    si,offset Responses    ;SI points to responses
  104.     mov    bx,offset DupList    ;BX points to duplist
  105. REDUNDANT:
  106.     LODSB            ;PUT [SI]=>AL, INC SI
  107.     MOV    DI,AX        ;COPY CHARACTER INTO DI
  108.     XLAT            ;[BX+AL]=>AL
  109.     CMP    AL,20H        ;DOES IT ALREADY EXIST
  110.     JZ    DUPLICATE    ;YES, PRINT DUPLICATE & END
  111.     MOV    BYTE PTR[BX+DI],20H    ;PUT 20H INTO DUPLIST
  112.     LOOP    REDUNDANT    ;LOOP UNTIL DONE
  113.     XOR    AX,AX        ;CLEAR AX
  114. ;[TH]    JMP    LEAVE        ;GO TO LEAVE AND RETURN
  115.     ret            ;[TH] hell with "classical" code.
  116.                 ;We don't worry about no msg ofs in dx
  117.                 ;since we're gonna go right to Wait
  118. ;====================================================================
  119. ; ERROR MESSAGE OUTPUTS
  120. ;
  121. MISSING:
  122. ;[TH]    MOV    AH,09H        ;
  123. ;[TH]    LEA    DX,[NONE+0100H]    ;
  124. ;[TH]    INT    21H        ;PRINT "MISSING ..."
  125. ;[TH]    MOV    AL,86H        ;SET AL TO ERROR(86H)
  126. ;[TH]    JMP    LEAVE        ;RETURN
  127.     mov    dx,offset None    ;'Missing reply parms'
  128.     jmp    short Leave    ;set AL to 86H and return
  129. ;
  130. INVALID:
  131. ;[TH]    MOV    AH,09H        ;
  132. ;[TH]    LEA    DX,[WRONG+0100H]
  133. ;[TH]    INT    21H        ;PRINT "INVALID ..."
  134. ;[TH]    MOV    AL,86H        ;SET AL TO ERROR(86H)
  135. ;[TH]    JMP    LEAVE        ;RETURN
  136.     mov    dx,offset Wrong    ;'Invalid parm'
  137.     jmp    short Leave    ;set AL to 86H and return
  138. ;
  139. DUPLICATE:
  140. ;[TH]    MOV    AH,09H        ;
  141. ;[TH]    LEA    DX,[DOUBLE+0100H]
  142. ;[TH]    INT    21H        ;PRINT "DUPLICATE ..."
  143.     mov    dx,offset Double    ;'Duplicate parm'
  144. Leave:                ;[TH]
  145.     MOV    AL,86H        ;SET AL TO ERROR(86H)
  146. ;
  147. ;[TH] LEAVE:
  148.     RET            ;RETURN
  149.  
  150. Input    endp
  151.  
  152. ;====================================================================
  153. ; START OF TIMING, KEYBOARD RESPONSE, AND CHARACTER CHECKING ROUTINE
  154. ;
  155. ;WAIT:    [TH] a reserved word in MASM 5.0
  156. Wait1    proc    near
  157.     XOR    AX,AX        ;CLEAR AX
  158.     MOV    AH,09H        ;
  159. ;[TH]    LEA    DX,ASKTHIS+0100H
  160.     mov    dx,offset AskThis    ;'RESPONSE:'
  161.     INT    21H        ;PRINT "RESPONSE:"
  162.  
  163. ;Toad Hall Note:  I replaced the CPU-dependent timer loop with a direct
  164. ;DOS master clock watching procedure.  We'll check every 1/18 second, ok?
  165. ;This'll work fine (and not be machine speed dependent) if you're
  166. ;PC-compatible.  If not .. sigh .. comment out MY code and put the
  167. ;patched loop back in.
  168.  
  169.     les    si,Clock    ;get seg, ofs of master clock, DOS Page 0
  170.     ASSUME    ES:Nothing    ;keep MASM happy
  171.  
  172.     mov    cx,182        ;set timer counter to 10 seconds (10*18.2)
  173.     mov    bh,18        ;a handy 18 divisor
  174. Seconds:
  175.     mov    ax,ES:[si]    ;snarf current clock lower word
  176. Tick18:    cmp    ax,ES:[si]    ;same as last check?
  177.     je    Tick18        ; yep, wait for a 1/18 second tick
  178.  
  179. ;Now check our user for any kbd input
  180.     mov    ah,0BH        ;check kbd status
  181.     int    21H
  182.     cmp    al,0ffh        ;FF=ready, 00=not
  183.     je    Process        ; Yep, go process input
  184.  
  185. ;No input, keep ticking
  186.     mov    ax,cx        ;get counter
  187.     div    bh        ;mod 18
  188.     or    ah,ah        ;any remainder?
  189.     jne    NoDot        ;not a full second of ticks yet
  190. ;[TH]    mov    dx,offset TimeTick    ;' .' display a tick
  191. ;[TH]    mov    ah,09H        ;display text
  192.     mov    dl,'.'        ;display a tick
  193.     mov    ah,2        ;display single-char output
  194.     int    21H
  195. NoDot:
  196.     loop    Seconds        ;loop for 10 seconds
  197.     jmp    short Default    ;..and assume Default at the timeout
  198.  
  199.  
  200. Comment | [TH] all this CPU-dependent stuff commented out
  201.     MOV    CH,0AH        ;SET TIMER TO 10+1
  202.  
  203. SECONDS:MOV    CL,02H        ;SET TWIDDLE TO 2
  204. HALFSEC: MOV    BX,65500    ;SET TWIDDLE COUNT
  205. TWIDDLE: DEC    BX        ;BX-1=>BX
  206. ;[TH]    CMP    BX,0000        ;IS BX ZERO
  207.     or    bx,bx        ;is BX zero?
  208.     JNZ    TWIDDLE        ;NO, CONTINUE TWIDDLE
  209.     MOV    AH,0BH        ;
  210.     INT    21H        ;CHECK FOR INPUT READY
  211.     CMP    AL,0ffh    ;-1    ;-1=READY, 00=NOT
  212.     JZ    PROCESS        ;YES, PROCESS INPUT
  213. RETURN: DEC    CL        ;CL-1=>CL
  214. ;[TH]    CMP    CL,00        ;IS CL ZERO
  215.     or    cl,cl        ;is outer counter zeroed yet?
  216.     JNZ    HALFSEC        ;NO, CONTINUE TIMER
  217. ;[TH]    MOV    AH,09H        ;
  218. ;[TH]    LEA    DX,TIMETICK+0100H
  219. ;[TH]    mov    dx,offset TimeTick    ;' .'
  220.     mov    dl,'.'        ;timetick
  221.     mov    ah,2        ;display single-char output
  222.     INT    21H        ;PRINT " ."
  223.     DEC    CH        ;CH-1=>CH
  224. ;[TH]    CMP    CH,00        ;IS CH ZERO
  225.     or    ch,ch        ;is second counter zeroed?
  226.     JZ    DEFAULT        ;YES, PROCESS DEFAULT
  227. ;[TH] If you tell MASM to jump short, it'll prevent dumb NOPs
  228.     JMP    short SECONDS    ;CONTINUE TIMER LOOP
  229. End of tick loop commented-out code |
  230.  
  231. ;====================================================================
  232. ; PROCESS KEYBOARD INPUT - CHECK IF VALID RESPONSE
  233. ;
  234. PROCESS:
  235.     PUSH    BX        ;SAVE BX
  236.     PUSH    CX        ;  "  CX
  237. ;[TH] no need to save DX or DI as far as I can see..
  238. ;[TH]    PUSH    DI        ;  "  DI
  239. ;[TH]    PUSH    DX        ;  "  DX
  240.     XOR    DX,DX        ;CLEAR DX
  241.     MOV    AH,08H        ;
  242.     INT    21H        ;GET CHARACTER IN AL
  243. ;[TH]    LEA    BX,TABLE+0100H    ;POINT BX TO TABLE
  244.     mov    bx,offset Table    ;Point BX to table
  245.     XLAT            ;[BX+AL]=>AL
  246. ;[TH]    CMP    AL,00        ;